package com.duoduo.admin.entity;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import io.swagger.v3.oas.annotations.media.Schema;

import org.hibernate.Hibernate;
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import jakarta.persistence.Column;
import jakarta.persistence.ConstraintMode;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.FetchType;
import jakarta.persistence.ForeignKey;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToMany;
import lombok.Data;
import lombok.ToString;

@Entity
@Data
@EntityListeners(AuditingEntityListener.class)
public class SysMenu implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6728488025064109023L;
	@Id
   // @GeneratedValue(strategy = GenerationType.IDENTITY)
     /**
	 * 菜单id
	 */
	
	private Long id;
     /**
	 * 菜单名称
	 */
	private String name;
     /**
	 * 菜单权限标识
	 */
	private String permissions;
	private String component;
	/**
	 * 标题
	 */
	private String title;
	private Boolean hidden;
	private Boolean disabled;
	private String redirect;
	//跳转内部地址
	private String frameSrc;
	
	//跳转外部地址
	private String externalLink;
	  /**
		 * 类型 菜单 内嵌页面
		 */
	private String type;
     /**
	 * 前端URL
	 */
	private String path;
     /**
	 * 父菜单ID
	 */
    @Column(name = "parent_id", updatable = false)
	private Long parentId;
     /**
	 * 图标
	 */
	private String icon;
     /**
	 * 排序值
	 */
	private String sortOrder;
     /**
	 * 路由缓存
	 */
	private Integer keepAlive;
     /**
	 * 逻辑删除标记(0--正常 1--删除)
	 */
	private Boolean delFlag;
     /**
	 * 创建人
	 */
    @CreatedBy
	private String createBy;
     /**
	 * 创建时间
	 */
    @CreatedDate
	private LocalDateTime createTime;
     /**
	 * 修改人
	 */
    @LastModifiedBy
	private String updateBy;
     /**
	 * 更新时间
	 */
    @LastModifiedDate
	private LocalDateTime updateTime;
    
    @OneToMany(fetch = FetchType.LAZY)
    @BatchSize(size = 30)
    @Fetch(value = FetchMode.SELECT)
    @JoinColumn(name = "parent_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT), insertable = false, updatable = false)
    @ToString.Exclude
    private Set<SysMenu> children;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
        SysMenu menu = (SysMenu) o;
        return id != null && Objects.equals(id, menu.id);
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }

}
